
import api from '../../utils/api'
import {formatRichText} from '../../utils/util'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageBaseURL: app.imageBaseURL,
    imageResizeParams: app.imageResizeParams,
    list:[],
    pagesize:10,
    page:1
  },
  goThemeClass(e){
    wx.navigateTo({
      url: '/pages/index_theme_class/index?id=' + e.currentTarget.dataset.id + '&title=' + e.currentTarget.dataset.title + '&img='  + e.currentTarget.dataset.img
    })
  },
  //列表信息
  async getList () {
    let data={}
    data['flag'] = 'theme'
    data['action'] = 'theme_list'
    data['page'] = this.data.page
    data['pageSize'] = this.data.pagesize
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      if( result && result.length>0 ){
        result.forEach((item,index) => {
          item.img = this.loadImg(item.img)
          item.intro = formatRichText(item.intro)
        })
        let page = this.data.page+1
        let str = 'list['+(this.data.page-1)+']'
        this.setData({
          [str]:result,page
        })
      }
    }else {
      Toast(message)
    }
  },
  //图片加载
  loadImg(img){
    let url =  api.checkurl(img)
    return url
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})